package api

import (
	"gitee.com/zatto/project/devcloud/mcenter/apps/token"
	"github.com/emicklei/go-restful/v3"
	"github.com/infraboard/mcube/http/restful/response"
)

func (h *handler) IssueToken(r *restful.Request, w *restful.Response) {
	// 获取body参数
	in := token.NewIssueTokenRequest()
	err := r.ReadEntity(in)
	if err != nil {
		response.Failed(w, err)
		return
	}

	// 颁发token
	tk, err := h.service.IssueToken(r.Request.Context(), in)
	if err != nil {
		response.Failed(w, err)
		return
	}

	w.WriteEntity(tk)
}
